package com.lark.algorithm.study.set;

import com.lark.algorithm.study.linkedlist.LinkedList;

/**
 * @author btmood
 * @version 1.0
 * @apiNote
 * @since 2024-05-06 20:34
 */
public class LinkedListSet<E> implements Set<E>{

    private LinkedList<E> list;

    public LinkedListSet() {
        list = new LinkedList<>();
    }

    @Override
    public void add(E e) {
        // 防止添加重复元素
        if (!list.contains(e)) {
            // 在头节点添加元素时间最少
            list.addFirst(e);
        }
    }

    @Override
    public void remove(E e) {
    }

    @Override
    public boolean contains(E e) {
        return list.contains(e);
    }

    @Override
    public int getSize() {
        return list.getSize();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }
}
